﻿using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;

namespace Bzstd;

public static class Program
{
	[STAThread]
	public static int Main()
	{
		try
		{
			var dest = Path.GetFullPath("P2WorkshopKit.exe");
			var src = Directory.GetDirectories("..\\")
				.SelectMany(d => Directory.GetFiles(d, "P2WorkshopKit.exe"))
				.Where(f => Path.GetFullPath(f) != dest)
				.OrderByDescending(f => new FileInfo(f).LastWriteTime)
				.FirstOrDefault();
			if (src != null)
			{
				File.Copy(src, dest, true);
			}

			if (!File.Exists(dest))
			{
				throw new Exception("未找到P2WorkshopKit.exe");
			}

			Process.Start(new ProcessStartInfo(dest));
			return 0;
		}
		catch (Exception e)
		{
			MessageBox.Show(e.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
			return 1;
		}
	}
}
